home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: jlilley@ix.netcom.com (John Lilley)
- Newsgroups: comp.lang.c++
- Subject: Re: RTTI and MSVC 4.0 examples sought
- Date: 14 Mar 1996 05:03:50 GMT
- Organization: Netcom
- Message-ID: <4i89bm$57m@ixnews3.ix.netcom.com>
- References: <313F912F.39D2@vream.com> <4hpv0r$7sv@druid.borland.com>
- NNTP-Posting-Host: den-co20-12.ix.netcom.com
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=US-ASCII
- X-NETCOM-Date: Wed Mar 13 9:03:50 PM PST 1996
- X-Newsreader: WinVN 0.99.7
-
- In article <4hpv0r$7sv@druid.borland.com>, pete@borland.com says...
- >
- >In article <313F912F.39D2@vream.com>, tnewark@vream.com says...
- >>
- >>I'm looking for some examples of using RTTI with MSVC 4.0.
- >>
- >>The problem I'm specifically trying to solve is that I want to implement
- >>IsKindOf(Ptr, class) where I return true if a ptr is type class or a
- >>subclass of class, and false otherwise.
- >>
- >>MicroSoft's documentation is very weak on the RTTI subject and type_info
- >>class, especially about such things as collating order (what exactly is
- >>it?)
- >
- >#define IsKindOf(Ptr,class) dynamic_cast<class *>(Ptr)
- >}
- >
- >I haven't tried this with MSVC 4.0. However, it should work on any compiler
- >that implements RTTI correctly.
- >
-
- Be careful here... the VC++ 4.0 docs state the the run-time type info
- used for MFC is NOT C++ RTTI, but some other mechanism. IsKindOf in
- MFC uses the home-grown RTTI, not C++ RTTI. It takes a pointer to
- CRunTimeClass, which can be obtained with the RUNTIME_CLASS macro,
- and I quoth from the doc...
-
- RUNTIME_CLASS( class_name )
- Parameters
- class_name The actual name of the class (not enclosed in quotation marks).
- Remarks
- Use this macro to get the run-time class structure from the name of a C++
- class.
- RUNTIME_CLASS returns a pointer to a CRuntimeClass structure for the class
- specified by class_name. Only CObject-derived classes declared with
- DECLARE_DYNAMIC, DECLARE_DYNCREATE, or DECLARE_SERIAL will return pointers to
- a CRuntimeClass structure.
- For more information, see the article CObject Class in Programming with MFC.
- Example
- // example for RUNTIME_CLASS
- CRuntimeClass* prt = RUNTIME_CLASS( CAge );
- ASSERT( lstrcmp( prt->m_lpszClassName, "CAge" ) == 0 );
-
-
- So to integrate with MFC's runtime-type-info, derive from CObject and use
- one of the DECLARE_* magic macros.
-
- john lilley
-
-